{extend name="base"}
{block name="title"}俱乐部开服列表{/block}
{block name="head"}
<style type="text/css">
.border-table tbody th {text-align: center;}
*{font-size: 13px;}
</style>
<link rel="stylesheet" type="text/css" href="__STATIC__/linux/xrtem.css">
<script type="text/javascript" src="__STATIC__/linux/xrtem.js"></script>

{/block}
{block name="body"}
<body class="mainbody">
<form>
    <!--导航栏-->
    <div class="location">
        <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
        <a href="{:url('index/home')}" class="home"><i class="iconfont icon-home"></i><span>首页</span></a>
        <i class="arrow iconfont icon-arrow-right"></i>
        <span>俱乐部开服列表</span>
    </div>
    <!--/导航栏-->
 <div class="table-container">
    <div class="right panel-heading">
        <input type="button" {egt name="Status" value="1" } class="btn none" {else} class="btn green" {/egt} value="配置服务" onclick="show(1)" data="1">
    </div>
   
    <div class="panel panel-primary" id="panels">
        <div class="panel-heading head">
            <input type="button"  {egt name="linuxid" value="200" } class="btn none" {else} class="btn" {/egt} value="检测连接状态" onclick="show(200)" data="200">
            <input type="button"  {egt name="linuxid" value="3" } class="btn none" {else} class="btn" {/egt} value="执行Go命令" onclick="show(3)" data="3">
            <input type="button"  {egt name="linuxid" value="4" } class="btn none" {else} class="btn" {/egt} value="执行Docker命令" onclick="show(4)" data="4">
            <input type="button"  {egt name="linuxid" value="5" } class="btn none" {else} class="btn" {/egt} value="执行Git命令" onclick="show(5)" data="5">
            <input type="button"  {egt name="linuxid" value="6" } class="btn none" {else} class="btn" {/egt} value="执行镜像命令" onclick="show(6)" data="6">
            <input type="button"  {egt name="linuxid" value="7" } class="btn none" {else} class="btn" {/egt} value="执行修改配置文件命令" onclick="show(7)" data="7">
            <input type="button"  {egt name="linuxid" value="8" } class="btn none" {else} class="btn" {/egt} value="结束链接" onclick="show(8)" data="8">
            
        </div>
        <div class="panel-body">
              <div id="terminal"></div>
        </div>
        
    </div>



  <script type="text/javascript">
      var window_width = $(window).width()-200;
      var window_height = $(window).height()-50;
      var term = new Terminal(
            {
                cols: Math.floor(window_width/9),
                rows: Math.floor(window_height/20),
                useStyle:false,
                convertEol: true,
                cursorBlink:false,
                rendererType: "canvas",
                theme:{
                    foreground: 'yellow',
                    background: 'rgba(6,1,1,0.55)',
                }
            }
    );
    term.open(document.getElementById('terminal'));
      function show($id){
          var tp = $id;
          var name = $("input[onclick='show("+tp+")']").val();
          var myDate = new Date();  
          var h = myDate.getHours();//获取当前小时数(0-23)
          var m = myDate.getMinutes();//获取当前分钟数(0-59)
          var s = myDate.getSeconds();//获取当前秒
          if (tp == 1) {
              dialog({
                width:500,
                height:200,
                title: '输入对应的服务信息',
                content: 
                         '<input type="text" class="input a"  style="width:490px;" placeholder="请输入用户名" />\n'+
                         '<input type="text" class="input b"  style="width:490px;" placeholder="请输入密码" />\n'+
                         '<input type="text" class="input c"  style="width:490px;" placeholder="请输入IP地址" />\n'+
                         '<input type="text" class="input d"  style="width:490px;" placeholder="请输入端口" />'
                          ,
                okValue: '确定',
                cancelValue: '取消',
                cancel: function () {},
                ok: function () {
                  var a = $(this.node);
                  var root = $('.input.a', a).val();
                  var pwd = $('.input.b', a).val();
                  var host = $('.input.c', a).val();
                  var port = $('.input.d', a).val();
                  $.ajax({
                    url:"{:url('server.linusrv/index')}",
                    type:"POST",
                    data:{type:tp,root:root,pwd:pwd,host:host,port:port},
                    success:function(res){
                        alert(res.error)
                        location.reload();
                    }
                  });
              }
            }).showModal();
          }else if (tp == 5) {
            dialog({
              width:500,
              height:100,
              title: '输入Git地址',
              content: '<input type="text" class="input"  style="width:490px;" placeholder="请输入Git地址" />',
              okValue: '确定',
              cancelValue: '取消',
              cancel: function () {},
              ok: function () {
                var a = $(this.node);
                var p = $('.input', a);
                var v = p.val();
                term.writeln("=============="+name+"中......==============");
                term.writeln("开始时间："+h+':'+m+':'+s);
                var ajaxTimeoutTest = $.ajax({
                url:"{:url('server.linusrv/index')}",
                type:"POST",
                timeout : 20000, //超时时间设置，单位毫秒
                data: {type:tp,git:v},
                success:function (data) {
                  // var data = JSON.parse(res);
                  if (data['errno'] == 101) {
                       term.writeln("error:\n"+data["data"]["err"]);
                  }else{
                    console.log(data);
                    term.writeln("=============="+data["error"]+"==================");
                    term.writeln("成功执行:\n"+data["data"]["cmd"]);
                    term.writeln("错误信息:\n"+data["data"]["err"]);
                    var endDate = new Date();  
                    var eh = endDate.getHours();//获取当前小时数(0-23)
                    var em = endDate.getMinutes();//获取当前分钟数(0-59)
                    var es = endDate.getSeconds();//获取当前秒
                    term.writeln("结束时间:"+eh+':'+em+':'+es);
                    term.writeln("<<!--------------------------------------------------------------------------------------!>>");
                    term.writeln("\n");
                    $(".head").load(location.href+" .head");
                    }
                  
                  },
                error:function(jqXHR, textStatus, errorThrown){
                  if(textStatus=="timeout"){
                    var endDate = new Date();  
                    var eh = endDate.getHours();//获取当前小时数(0-23)
                    var em = endDate.getMinutes();//获取当前分钟数(0-59)
                    var es = endDate.getSeconds();//获取当前秒
                    term.writeln("=============="+name+"超时......==============");
                    term.writeln("结束时间:"+eh+':'+em+':'+es);
                    term.writeln("<<!--------------------------------------------------------------------------------------!>>");
                  }else{
                    alert(textStatus);
                  }
                },  
          
               });
                return false;
              }
            }).showModal();
          }else{
            term.writeln("=============="+name+"中......==============");
            term.writeln("开始时间："+h+':'+m+':'+s);
            var ajaxTimeoutTest = $.ajax({
              url:"{:url('server.linusrv/index')}",
              type:"POST",
              timeout:20000,
              data: {type:tp},

              success:function (data) {
                  // var data = JSON.parse(res);
                  if (data['errno'] == 101) {
                       term.writeln("error:\n"+data["data"]["err"]);
                  }else{
                    term.writeln("=============="+data["error"]+"==================");
                    term.writeln("===成功执行===:\n"+data["data"]["cmd"]);
                    term.writeln("===错误信息===:\n"+data["data"]["err"]);
                    var endDate = new Date();  
                    var eh = endDate.getHours();//获取当前小时数(0-23)
                    var em = endDate.getMinutes();//获取当前分钟数(0-59)
                    var es = endDate.getSeconds();//获取当前秒
                    term.writeln("结束时间:"+eh+':'+em+':'+es);
                    term.writeln("<<!--------------------------------------------------------------------------------------!>>");
                    term.writeln("\n");
                  }
                  
                  $linuxid = data['data']['linuxid'];
                  
                  $(".head").load(location.href+" .head");
                  
                },
              error:function(jqXHR, textStatus, errorThrown){
                  if(textStatus=="timeout"){
                    var endDate = new Date();  
                    var eh = endDate.getHours();//获取当前小时数(0-23)
                    var em = endDate.getMinutes();//获取当前分钟数(0-59)
                    var es = endDate.getSeconds();//获取当前秒
                    term.writeln("=============="+name+"超时......==============");
                    term.writeln("结束时间:"+eh+':'+em+':'+es);
                    term.writeln("<<!--------------------------------------------------------------------------------------!>>");
                  }else{
                    alert(textStatus);
                  }
                },
              });
            }
      }
  </script>
</div>
</form>

</body>
{/block}